package cate.common.table.farm.island.sheet;

import cate.common.table.ESheet;
import cate.common.table.farm.island.row.IslandGainGroupRow;
import cate.common.table.farm.island.row.IslandGainRow;
import cate.common.util.random.RWList;
import easy.java.dev.note.NoteClass;

import java.util.List;
import java.util.stream.Collectors;

@NoteClass(value = "迷失神庙增益组包")
public class IslandGainGroupSheet extends ESheet<IslandGainGroupRow> {

    @Override
    public String getSheetName() {
        return "迷失神庙增益组包";
    }

    /**
     * 从一个组包中随机不重复的增益
     *
     * @param gainList 当前拥有的增益
     * @param group 组
     */
    public void randomFuzhao(List<Integer> gainList, int group) {
        List<IslandGainGroupRow> collect = this.getList().stream()
                        .filter(a -> a.group == group && !gainList.contains(a.gainId))
                        .collect(Collectors.toList());
        RWList<IslandGainGroupRow> rwList = new RWList<>();
        rwList.setup(collect);
        IslandGainGroupRow row = rwList.get();
        if (row != null) {
            gainList.add(row.gainId);
        }
    }

    /**
     * 从一个组包中随机不重复的增益
     *
     * @param gainList 当前拥有的增益
     * @param group 组
     */
    public void randomFuzhao(IslandGainSheet gainSheet, List<Integer> gainList, int group) {
        List<IslandGainGroupRow> collect = this.getList().stream()
                .filter(a -> a.group == group && !gainList.contains(a.gainId))
                .collect(Collectors.toList());

        collect.removeIf(a -> {
            IslandGainRow islandGainRow = gainSheet.get(a.gainId);
            if (islandGainRow.camps.isEmpty()) {
                return false;
            }
            return true;
        });
        RWList<IslandGainGroupRow> rwList = new RWList<>();
        rwList.setup(collect);
        IslandGainGroupRow row = rwList.get();
        if (row != null) {
            gainList.add(row.gainId);
        }
    }
}
